﻿using System.Web.Mvc;

namespace IterationLife.Extensions.MvcApi
{
    /// <summary>
    /// MVC API 控制器基类
    /// </summary>
    public class MvcApiController : Controller
    {
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="code">返回码</param>
        protected ActionResult Ok(string message = "", string code = "")
        {
            return new MvcApiResult<object> { Data = null, Code = code, Message = message };
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="data">返回数据</param>
        /// <param name="message">消息</param>
        /// <param name="code">返回码</param>
        /// <returns></returns>
        protected ActionResult Ok<TData>(TData data = default(TData), string message = "", string code = "")
        {
            return new MvcApiResult<TData> { Data = data, Code = code, Message = message };
        }
    }
}
